package Practice08.test6;

import java.util.ArrayList;
import java.util.List;

public class EmployeeUtils {
    private List<Employee> list = new ArrayList<>();

    public EmployeeUtils(List<Employee> list) {
        this.list = list;
    }

    //功能不完整，意思意思
    //增
    public String add(int id, String name, String location, double salary){
        for (Employee e: list) {
            if (e.getId() == id){
                return "该id已存在";
            }

        }
        list.add(new Employee(id,name,location,salary));
        return "增加完成";
    }

    //删
    public void deleteById(int id){
        list.removeIf(e -> e.getId() == id);
    }

    //改
    public void updateById(int id, String name, String location, double salary){
        list.removeIf(e -> e.getId() == id);
        list.add(new Employee(id,name,location,salary));
    }

    //查
    public Employee selectById(int id){
        for (Employee e: list) {
            if (e.getId() == id){
                return e;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return "EmployeeUtils{" +
                "list=" + list +
                '}';
    }

    public List<Employee> getList() {
        return list;
    }

    public void setList(List<Employee> list) {
        this.list = list;
    }
}
